# @FileName  : test7.py
# @Time      : 2025/2/23 05:03
# @Author    : LuZhaoHui
# @Software  : PyCharm

# import requests
# import json
#
# package_name = 'numpy'
# url = f'https://pypi.org/pypi/{package_name}/json'
# response = requests.get(url)
# data = response.json()
# latest_version = data['info']['version']
# print(f'The latest version of {package_name} is {latest_version}')

from packaging import version
from packaging.specifiers import SpecifierSet
from packaging.requirements import Requirement
import requests
import json

packetName = 'torch'
url = 'https://pypi.org/pypi/%s/json' % (packetName)
response = requests.get(url, headers={'Accept': 'application/json'})
data = response.json()
versions = data['releases'].keys()
print(versions)  # 打印所有版本号，但不直接比较版本号大小。如果你需要比较版本号，可以使用以下方法：

# 创建一个版本号比较器，例如只选择大于等于2.0的版本号：
# specifier = SpecifierSet(">=2.0")  # 只选择2.0及以上版本
# filtered_versions = [v for v in versions if specifier.contains(version.parse(v))]
# filtered_versions = [v for v in versions]
# print(filtered_versions)  # 打印过滤后的版本号列表
